package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysPhoto;
import com.ruoyi.system.service.ISysPhotoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 照片Controller
 * 
 * @author ruoyi
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/system/photo")
public class SysPhotoController extends BaseController
{
    @Autowired
    private ISysPhotoService sysPhotoService;

    /**
     * 查询照片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysPhoto sysPhoto)
    {
        startPage();
        List<SysPhoto> list = sysPhotoService.selectSysPhotoList(sysPhoto);
        return getDataTable(list);
    }

    @GetMapping("/works")
    public List works(String worksKey)
    {
        List<SysPhoto> list = sysPhotoService.selectSysPhotoByWorksKey(worksKey);
        return list;
    }

    /**
     * 导出照片列表
     */
    @Log(title = "照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPhoto sysPhoto)
    {
        List<SysPhoto> list = sysPhotoService.selectSysPhotoList(sysPhoto);
        ExcelUtil<SysPhoto> util = new ExcelUtil<SysPhoto>(SysPhoto.class);
        util.exportExcel(response, list, "照片数据");
    }

    /**
     * 获取照片详细信息
     */
    @GetMapping(value = "/{photoKey}")
    public AjaxResult getInfo(@PathVariable("photoKey") String photoKey)
    {
        return success(sysPhotoService.selectSysPhotoByPhotoKey(photoKey));
    }

    /**
     * 作品获取照片
     */
    @GetMapping(value = "/getworksphote/{worksKey}")
    public List getPhotoByWorkKey(@PathVariable("worksKey") String worksKey)
    {
        List<SysPhoto> list = sysPhotoService.selectPhotoByWorksKey(worksKey);
        return list;
    }

    /**
     * 新增照片
     */
    @Log(title = "照片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPhoto sysPhoto)
    {
        return toAjax(sysPhotoService.insertSysPhoto(sysPhoto));
    }

    /**
     * 修改照片
     */
    @Log(title = "照片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPhoto sysPhoto)
    {
        return toAjax(sysPhotoService.updateSysPhoto(sysPhoto));
    }

    /**
     * 删除照片
     */
    @Log(title = "照片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{photoKeys}")
    public AjaxResult remove(@PathVariable String[] photoKeys)
    {
        return toAjax(sysPhotoService.deleteSysPhotoByPhotoKeys(photoKeys));
    }
}
